﻿using System.Collections.Generic;
using System.Xml.Linq;
using IcicleFramework.Entities;
using Microsoft.Xna.Framework;
using TiledLib;

namespace IcicleFramework.GameServices
{
    public delegate void GameObjectCreatedHandler(IGameObject newObject);

    public interface IGameObjectFactory : IGameService
    {
        /// <summary>
        /// An event that fires whenever a new IGameObject is created by this IGameObjectFactory.
        /// </summary>
        event GameObjectCreatedHandler OnGameObjectCreated;

        /// <summary>
        /// Gets or set the path (relative to the Content directory) of the XML file containing entity definitions.
        /// </summary>
        string PathToXML { get; set; }

        /// <summary>
        /// Generates the components for the given IGameObject, based on the definition provided in the XElement element.
        /// Each component generated is attached to the given IGameObject.
        /// </summary>
        /// <param name="gameObject">The parent for each of the components that will be generated.</param>
        /// <param name="element">The XElement containing the descriptions of the components to attach to the provided IGameObject.</param>
        void GenerateComponents(IGameObject gameObject, XElement element);

        /// <summary>
        /// Deep copies an existing <see cref="IGameObject"/> into a new one.
        /// </summary>
        /// <param name="toCopy">The <see cref="IGameObject"/> to deep copy.</param>
        /// <returns>A deep copy of the original <see cref="IGameObject"/>.</returns>
        IGameObject CopyExistingGameObject(IGameObject toCopy);

        /// <summary>
        /// Generates a new IGameObject with all associated components based on the provided object name (matching that in the entity XML file).
        /// </summary>
        /// <param name="objectName">The name of the IGameObject to create, corresponding to a name game object definition in the entity XML file.</param>
        /// <returns>The newly created IGameObject, or null if no matching object name was found in the entity XML file (or other errors).</returns>
        IGameObject GenerateGameObjectFromName(string objectName);

        /// <summary>
        /// Generates a new IGameObject at the given position with all associated components based on the provided object name (matching that in the entity XML file).
        /// </summary>
        /// <param name="objectName">The name of the IGameObject to create, corresponding to a name game object definition in the entity XML file.</param>
        /// <param name="position">The generated IGameObject will be positioned here immediately after its creation.</param>
        /// <returns>The newly created IGameObject, or null if no matching object name was found in the entity XML file (or other errors).</returns>
        IGameObject GenerateGameObjectFromName(string objectName, Vector2 position);
    }
}
